package com.example.drools.spring.yc.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.example.drools.spring.core.impl.ProductRuleEngineImpl;
import com.example.drools.spring.dao.RuleRepository;
import com.example.drools.spring.entity.CheckResult;
import com.example.drools.spring.entity.DroolModel;
import com.example.drools.spring.entity.DroolRule;
import com.example.drools.spring.entity.Product;
import com.example.drools.spring.entity.db.Rule;
import com.example.drools.spring.utils.JacksonUtil;
import com.example.drools.spring.yc.constants.StatusTag;
import com.example.drools.spring.yc.entity.YcEnterpriseEntity;
import com.example.drools.spring.yc.entity.YcUniqueEntity;
import com.example.drools.spring.yc.service.YcCheckNullService;
import com.example.drools.spring.yc.service.YcUniqueService;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.QueryResults;
import org.kie.api.runtime.rule.QueryResultsRow;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ddsyw
 * @version 1.0
 * @date 2021/12/28 5:24 下午
 */
@RequestMapping("/yc/test")
@Controller
@Slf4j
public class YcRuleController {

  @Resource
  private YcCheckNullService ycCheckNullService;

  @Resource
  private YcUniqueService ycUniqueService;

  @ResponseBody
  @RequestMapping("/checkNull")
  public String checkNull(@RequestBody List<Map<String,String>> maps){
    if (CollectionUtil.isEmpty(maps)) {
      return "param is null";
    }
    Map<String, List<Map<String, String>>> map = ycCheckNullService.checkNulls(maps);
    return "success:" + map.get(StatusTag.SUCCESS.getStatus()).size() + "; fail:" + map.get(StatusTag.FAIL.getStatus()).size();
  }


  @ResponseBody
  @RequestMapping("/uniqueCheck")
  public List<YcEnterpriseEntity> uniqueCheck(@RequestBody List<YcEnterpriseEntity> ycEnterpriseEntities){
    if (CollectionUtil.isEmpty(ycEnterpriseEntities)) {
      return Collections.EMPTY_LIST;
    }
    ycUniqueService.checkUnique(ycEnterpriseEntities, "enterpriseUniqueCheck");
    return ycEnterpriseEntities;
  }
}
